package com.example.contacts;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.example.contacts.DB.DBTool;
import com.example.contacts.sql_bean.People;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddActivity extends Activity{

	EditText addNameEditText;
	EditText addNumberEditText;
	EditText addNoteEditText;

	Button saveButton;
	Button cancelButton;

	OnClickListener listener=new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.button_add:
				if(addNameEditText.getText().toString().equals("")||addNumberEditText.getText().toString().equals("")){

					new  AlertDialog.Builder(AddActivity.this).setTitle("提示" ).setMessage("姓名或者电话不能为空" ).setPositiveButton("确定" ,  null ).show();  

				}
				else{
					Intent data=new Intent();
					data.putExtra("addname", addNameEditText.getText().toString());
					data.putExtra("addnumber", addNumberEditText.getText().toString());
					data.putExtra("addnote", addNoteEditText.getText().toString());
					setResult(RESULT_OK, data);
					finish();
					
				}
				break;
			case R.id.button_add_cancel:
				setResult(RESULT_CANCELED);
				finish();
				break;

			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add);
		//		Intent intent=this.getIntent();
		//		Bundle bundle=intent.getExtras();  
		//		dbTool=(DBTool) bundle.getSerializable("db");
		init();



	}

	private void init(){
		addNameEditText=(EditText)findViewById(R.id.editText_addname);
		addNumberEditText=(EditText)findViewById(R.id.editText_addnumber);
		addNoteEditText=(EditText)findViewById(R.id.editText_addnote);
		saveButton=(Button)findViewById(R.id.button_add);
		cancelButton=(Button)findViewById(R.id.button_add_cancel);
		saveButton.setOnClickListener(listener);
		cancelButton.setOnClickListener(listener);
	}

}
